package com.asiainfo.hybridapp.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.widget.Toast;

import com.asiainfo.hybridapp.activity.LocationActivity;
import com.asiainfo.hybridapp.service.MyNotificationListenService;
import com.asiainfo.hybridapp.service.NotifyIntentService;
import com.asiainfo.hybridapp.utils.AmapTest;
import com.framework.utils.ToastUtil;

public class BootBroadcastReceiver extends BroadcastReceiver {
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION)) {
            startNotificationListenService(context);
            Intent testIntent1 = new Intent(context, LocationActivity.class);
            context.startService(testIntent1);
            Intent testIntent = new Intent(context, NotifyIntentService.class);
            context.startService(testIntent);
            Toast.makeText(context, "boot completed action has got", Toast.LENGTH_LONG).show();
            ToastUtil.getInstance().showToast("程序自启动了");
            AmapTest.startLocation();
//			Intent mainActivityIntent = new Intent(context, MainActivity.class); // 要启动的Activity
//			mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//			context.startActivity(mainActivityIntent);

//            Intent service = new Intent(context, LiveService.class); // 要启动的service
//            context.startService(service);
        }
    }

    // 启动监听消息通知服务
    private void startNotificationListenService(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            Intent intent = new Intent(context,
                    MyNotificationListenService.class);
            context.startService(intent);
        } else {
            Toast.makeText(context, "手机的系统不支持此功能", Toast.LENGTH_SHORT).show();
        }
    }
}